<template>
  <div class="base-container">
    <t-form ref="form" :data="queryParams" label-width="80"
            @submit="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}"
            @reset="()=>{this.pagination.current=1;this.queryParams.pageNum=1;this.getList()}">
      <t-row style="border-bottom: 1px solid #E5E6EB;margin-bottom: 10px">
        <t-col :span="11" class="query-form-inline">
          <t-form-item label="研究方向" name="researchDirection">
            <t-input
              v-model="queryParams.researchDirection"
              clearable
              placeholder="请输入研究方向"
              style="width: 240px"
            />
          </t-form-item>
          <t-form-item label="研发需求" name="projectName">
            <t-input
              v-model="queryParams.projectName"
              clearable
              placeholder="请输入研发需求"
              style="width: 240px"
            />
          </t-form-item>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button theme="primary" type="submit">查询</t-button>
          <t-button theme="default" variant="outline" type="reset">重置</t-button>
        </t-col>
      </t-row>
    </t-form>
    <div class="btn-group-inline">
      <t-button @click="apply" variant="outline" theme="primary">
        <t-icon name="add" slot="icon"/>
        新增
      </t-button>
    </div>
    <t-table
      rowKey="id"
      :data="data"
      :columns="columns"
      hover
      :pagination="pagination"
      :loading="dataLoading"
    >
      <template #status="{ row }">
        <t-tag @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer"
               :theme="handleTheme(row.status, dict.type.ggxq_result_status)" variant="light">
          {{ row.status | filterByDict(dict.type.ggxq_result_status) }}
        </t-tag>
      </template>
      <template #projectName="{row}">
        <t-link @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_review=true" hover="color" theme="primary">{{row.projectName}}</t-link>
      </template>
      <template #op="{ row }">
        <t-button  @click="update(row)" size="small" variant="text"
                   class="t-button-link">
          <t-icon name="edit-1" slot="icon"/>
          编辑
        </t-button>
        <t-button size="small"
                  @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_detail=true"
                  variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
        <t-button
          theme="danger"
          @click="delObj(row)"
          size="small"
          variant="text" class="t-button-link">
          <t-icon name="delete" slot="icon"/>
          删除
        </t-button>
      </template>
    </t-table>
    <special-plan-detail-dialog :objId="dialog.objId" :header="dialog.header" :visible.sync="dialog.open_detail" v-if="dialog.open_detail">
    </special-plan-detail-dialog>
    <file-review :header="dialog.header" achievementType="xqzjb" :visible.sync="dialog.open_review" v-if="dialog.open_review" :objId="dialog.objId"></file-review>

  </div>
</template>

<script>
import fileReview from "../../cgzh/components/file-review.vue";
import specialPlanDetailDialog from "./components/special-plan-detail-dialog.vue";

export default {
  name: "special-plan-index",
  dicts: ['ggxq_result_status'],
  components: {
    fileReview,
    specialPlanDetailDialog
  },
  data() {
    return {
      dialog: {
        header: "",
        objId: null,
        open_detail: false,
        open_review: false,
      },
      serviceOptions: [],
      projectOptions: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        researchDirection: "",
        projectName: ""
      },
      data: [],
      columns: [
        {
          colKey: "projectName",
          title: "研发需求",
          align: "center"
        },
        {
          colKey: "researchDirection",
          title: "研究方向",
          align: "center"
        },
        {
          colKey: "introducer",
          title: "提出人",
          align: "center"
        },
        {
          colKey: "deptName",
          title: "所在单位",
          align: "center"
        },
        {
          colKey: "phone",
          title: "联系电话",
          align: "center"
        },
        {
          colKey: "status",
          title: "状态",
          align: "center",
          fixed: 'right'
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 140,
          fixed: 'right'
        }
      ],
      dataLoading: false,
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10, 20, 30, 50],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination, pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    apply(){
      this.$router.push({
        path:`/ggxq/other/special-plan/special-plan-apply/${Date.parse(new Date())}`,
      })
    },
    update(row){
      this.$router.push({
        path:`/ggxq/other/special-plan/special-plan-apply/${row.id}`,
      });
    },
    getList() {
      this.dataLoading = true;
      this.$api.ggxq.specialPlan.list(this.queryParams).then(response => {
        this.data = response.rows;
        this.pagination.total = response.total;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading = false;
        this.$message.error(e.toString());
      });
    },
    delObj(row){
      const confirmDia = this.$dialog.confirm({
        header: "系统提示",
        body: `是否确认删除成果名称为"${row.projectName}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })
          this.$api.ggxq.specialPlan.del(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }
          ).catch((e) => {
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        }
      });
    }
  }
};
</script>

<style scoped>

</style>
